<?php

namespace app\index\controller;

use app\index\model\Banner as BannerModel;
use app\index\model\Config as ConfigModel;
use app\index\model\PublicProject as PublicProjectModel;
use think\Controller;
use think\Request;

class Social extends BaseController
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $banner = BannerModel::getBanner('social');
        $this->assign('banner', $banner);
    }

    /**
     * 公益理念
     * @return mixed
     */
    public function philosophy()
    {
        $philosophy = ConfigModel::getBaseValue('public_philosophy');
        $philosophy = $this->changeResponse($philosophy);
        $this->assign('philosophy', $philosophy);
        return $this->fetch('public_philosophy');
    }

    /**
     * 公益项目
     * @return mixed
     */
    public function project()
    {
        $projects = PublicProjectModel::getProjects();
        $projects = $this->changeResponses($projects);
        $totalPage = $projects->lastPage();
        $currentPage = $projects->currentPage();
        $this->paginate($totalPage, $currentPage);
        $this->assign('projects', $projects);
        return $this->fetch('public_project');
    }

    /**
     * 项目详情
     */
    public function projectDetail($id = 0)
    {
        $project = PublicProjectModel::getById($id);
        $project = $this->changeResponse($project);
        $preId = PublicProjectModel::getPreId($id);
        $nextId = PublicProjectModel::getNextId($id);
        $this->assign('project', $project);
        $this->assign('preId', $preId);
        $this->assign('nextId', $nextId);
        return $this->fetch('project_detail');
    }
}
